package ruan_kao;

class Product {
    private String partA;
    private String partB;

    public Product() {
    }

    public void setPartA(String s) {
        partA = s;
    }

    public void setPartB(String s) {
        partB = s;
    }
}

interface Builder {
    public void buildPartA(); //1

    public void buildPartB();

    public Product getResult(); //2
}

class ConcreteBuilder1 implements Builder {
    private Product product;

    public ConcreteBuilder1() {
        product = new Product();
    }

    @Override
    public void buildPartA() {
        product.setPartA("Component A"); //3
    }

    @Override
    public void buildPartB() {
        product.setPartB("Component B"); //4
    }

    @Override
    public Product getResult() {
        return product;
    }
}

//class ConcreteBuilder2 implements Builder {
//代码省略
//}

class Director {
    private Builder builder;

    public Director(Builder builder) {
        this.builder = builder;
    }

    public void construct() {
        builder.buildPartA(); //5
    }
}

class Test {
    public static void main(String[] args) {
        Director director1 = new Director(new ConcreteBuilder1());
        director1.construct();
    }
}
